package io.github.junxworks.qt.utils;

import io.github.junxworks.ep.core.orm.annotations.Column;
import io.github.junxworks.junx.core.util.ObjectUtils;
import io.github.junxworks.qt.modules.tushare.entity.DStockTradeDaily;

public class ObjectDescUtils {

	public static String desc(Class<?> clazz) throws Exception {
		String head = """
				<colgroup>
				  <col width="200">
				  <col width="200">
				  <col>
				</colgroup>
				<thead>
					<tr>
						<th>字段名</th>
						<th>字段类型</th>
						<th>字段备注</th>
					</tr>
				</thead>
				""";
		StringBuilder body = new StringBuilder("<tbody>");

		ObjectUtils.mirror().on(clazz).reflectAll().fields().forEach(f -> {
			body.append("<tr>");
			body.append("<td>").append(f.getName()).append("</td>");
			body.append("<td>").append(f.getType().getCanonicalName()).append("</td>");
			Column c = f.getAnnotation(Column.class);
			body.append("<td>").append(c.comment()).append("</td>");
			body.append("</tr>");
		});
		body.append("</tbody>");
		String res = head + body.toString();
		return res;
	}

	public static void main(String[] args) throws Exception {
		System.out.println(desc(DStockTradeDaily.class));
	}

}
